package de.teamgamma.cansat.groundstation.control;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.border.Border;

import de.szut.gui.language.Languages;
import de.teamgamma.cansat.groundstation.main.MainFrame;
import de.teamgamma.cansat.groundstation.options.OptionKeys;

/**
 * Class that controls the GUI
 * @author Marc Huisinga
 *
 */

public class GUIController {
	/**
	 * Default Font used in the program
	 */
	public static final Font COMPONENTFONT = new Font("Tahoma", Font.PLAIN, 11);
	/**
	 * Default Border used in the program
	 */
	public static final Border COMPONENTBORDER = BorderFactory.createLineBorder(Color.black);
	
	private MainFrame mainFrame;
	private JComponent currentPanel;
	private Languages languages;

	/**
	 * Starts the GUI
	 */
	public void startGUI() {
		setLanguages(new Languages());
		languages.addLanguage("German");
		languages.addLanguage("French");
		languages.addLanguage("Russian");
		languages.addLanguage("Polish");
		String language = Controller.getInstance().getOptions().getOptionValue(OptionKeys.LANGUAGE);
		if (language != "0") {
			languages.setCurrentLanguage(language);
		}
		mainFrame = new MainFrame();
		mainFrame.startMainFrame();
		currentPanel = (JPanel) mainFrame.getContentPane();
	}
	
	/**
	 * Disposes the MainFrame
	 */
	public void closeMainFrame() {
		WindowEvent wev = new WindowEvent(mainFrame, WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
	}
	
	/**
	 * Toggles the current panel of MainFrame
	 * @param newPanel panel to toggle to
	 */
	public void toggleCurrentPanel(JComponent newPanel) {
		mainFrame.remove(currentPanel);
		mainFrame.setContentPane(newPanel);
		mainFrame.revalidate();
		mainFrame.repaint();
		currentPanel = newPanel;
	}
	
	/**
	 * Gets the main frame
	 * @return main frame
	 */
	public MainFrame getMainFrame() {
		return mainFrame;
	}

	/**
	 * Sets the main frame
	 * @param mainFrame
	 */
	public void setMainFrame(MainFrame mainFrame) {
		this.mainFrame = mainFrame;
	}
	
	/**
	 * Gets the languages of the gui
	 * @return languages
	 */
	public Languages getLanguages() {
		return languages;
	}

	/**
	 * Sets the languages of the gui
	 * @param languages
	 */
	public void setLanguages(Languages languages) {
		this.languages = languages;
	}
}
